<!DOCTYPE HTML>
<html >
<head>
    <meta charset="UTF-8">
    <title>My WebSocket</title>
</head>

<body style="text-align:center">
我是用户0<br/>
信息:
<span id="msg"></span>
<div id="message">
</div>
</body>
<script src="https://cdn.bootcss.com/stomp.js/2.3.3/stomp.js"></script>
<script src="https://cdn.bootcss.com/sockjs-client/1.1.4/sockjs.js"></script>
<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    // 初始化 ws 对象
    var ws = new WebSocket('ws://8.140.181.206:15674/ws');

    // 获得Stomp client对象
    var client = Stomp.over(ws);

    // 定义连接成功回调函数
    var on_connect = function(x) {
        //data.body是接收到的数据
        client.subscribe("felix-queue", function(data) {
            var msg = data.body;
            $("#msg").text(msg);
        });
    };

    // 定义错误时回调函数
    var on_error =  function() {
        console.log('error');
    };
    // 连接RabbitMQ
    client.connect('zcx', '123456', on_connect, on_error, '/');
</script>
</html>